<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>存款业务</title>
    <!--    link用于定义链接的文件和html文档之间的关系 stylesheet的意思就是样式调用-->
    <!--    media 区分调用那个css样式 all 用于所有设备类型-->
    <link rel="stylesheet" href="../layui/css/layui.css" media="all">
    <script src="../layui/layui.js" charset="utf-8"></script>
    <script src="../jQuery/jquery-1.11.2.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/font.css">
</head>
<body>
<blockquote class="layui-elem-quote news_search" style="overflow-y:visible;overflow-x:visible;">
<!--数据表格-->
<script type="text/html" id="Trans_search">
    <!--多条件查询层-->
    <div  class="layui-input-inline"  style="float: left">
        <form class="layui-form layui-col-md12 x-so" >
            业务类型：
            <div  class="layui-input-inline">
                <select name="businType" id="rigType">
                    <option value="">---请选择---</option>
                    <option value="1">定期</option>
                    <option value="2">活期</option>
                </select>
            </div>
            到期时间：
            <div class="layui-input-inline">
                <input type="date" id="expiryDate" name="expiryDate" placeholder="请输入到期时间" autocomplete="off" class="layui-input"/>
            </div>
            <button id="search" class="layui-btn layui-btn-primary layui-bg-gray" lay-submit data-type="reload" lay-filter="provinceSearch">
                <i class="layui-icon">&#xe615;</i>
            </button>
        </form>
    </div>
    <!--头部按钮-->
    <div class="layui-btn-container layui-input-inline" style="margin-left: 150px">
        <button class="layui-btn layui-btn-danger" lay-event="batchDel">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn layui-btn-normal" lay-event="add">
            <i class="layui-icon">&#xe654;</i>添加
        </button>
        <button class="layui-btn layui-btn-normal" lay-event="okk">
            <i class="layui-icon">&#xe605;</i>结算
        </button>
    </div>
    <!--多条件查询结束-->
</script>
<table class="layui-hide" id="DeposiTable" lay-filter="DeposiList"></table>
<!-- 添加/修改界面开始 -->
<div id="data-main" style="display: none;">
    <div style="margin-left: 120px;margin-top: 25px">
        <form class="layui-form" id="DeposiForm" method="post" lay-skin="line" lay-filter="DeposiFormTest">
            <div class="layui-form-item">
                <div class="layui-inline"  style="display: none">
                <label class="layui-form-label">存款ID</label>
                <div class="layui-input-inline" >
                    <input name="deposiId" lay-verify="required" value="1" placeholder="请输入存款ID" autocomplete="off" class="layui-input"/>
                </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label" >流出账户</label>
                    <div class="layui-input-inline">
                        <select name="caId" id="caId">
                            <option  value="">---请选择---</option>
                        </select>
                    </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label" >流入账户</label>
                    <div class="layui-input-inline">
                        <select name="caIds" id="caIds">
                            <option  value="">---请选择---</option>
                        </select>
                    </div>
                </div>
                <div class="layui-inline">
                    <label class="layui-form-label">基金ID</label>
                    <div class="layui-input-inline" >
                        <select name="fundId" class="layui-inline" id="fundId">
                            <option id="option" value="">---请选择---</option>
                        </select>
                    </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label" >存款金额</label>
                    <div class="layui-input-inline" >
                    <input type="text" name="depMoney" lay-verify="required" placeholder="请输入存款金额" autocomplete="off" class="layui-input"/>
                </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label layui-icon" >业务类型</label>
                <div class="layui-input-inline" >
                    <select name="businType" class="layui-inline">
                        <option value="">---请选择---</option>
                        <option value="1">定期</option>
                        <option value="2">活期</option>
                    </select>
                </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label" >到期日期</label>
                <div class="layui-input-inline" >
                    <input type="date" name="expiryDate" lay-verify="required" placeholder="请输入到期日期" autocomplete="off" class="layui-input"/>
                </div>
                </div>
            </div>

            <div class="layui-form-item">
                <div class="layui-inline">
                <label class="layui-form-label layui-icon" >是否处理</label>
                <div class="layui-input-inline" >
                    <select name="handIf" class="layui-inline">
                        <!--<option value="">-&#45;&#45;请选择-&#45;&#45;</option>-->
                        <!--<option value="1">是</option>-->
                        <option value="2">未处理</option>
                    </select>
                </div>
                </div>
                <div class="layui-inline" style="display: none">
                <label class="layui-form-label" >所含利息</label>
                <div class="layuit-inline" >
                    <input type="text" name="incl" placeholder="请输入所含利息" autocomplete="off" class="layui-input"/>
                </div>
                </div>

                <div class="layui-inline">
                <label class="layui-form-label" >业务日期</label>
                <div class="layui-input-inline" >
                    <input type="date" name="businTime" lay-verify="required" placeholder="请输入业务日期" autocomplete="off" class="layui-input"/>
                </div>
                </div>

                <div class="layui-inline" style="display: none">
                <label class="layui-form-label" >资金调拨方向</label>
                <div class="layui-inline" >
                    <input type="text" name="dofa" placeholder="请输资金调拨方向" autocomplete="off" class="layui-input"/>
                </div>
                </div>
            </div>

            <div class="layui-form-item layui-col-md4 layui-col-md-offset4">
                <div class="layui-input-block" >
                    <button class="layui-btn layui-bg-blue" lay-submit lay-filter="formSave">保存</button>
                    <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                </div>
            </div>

    </form>
</div>
</div>
<!-- 添加/修改界面结束 -->

<!--<script type="text/html" >
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="batchDel">批量删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe615;</i>添加</button>
    </div>
</script>-->
<!-- 行中操作按钮[仅对本行操作] -->
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal layui-icon layui-icon-edit" lay-event="update">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs layui-icon layui-icon-delete" lay-event="delete">删除</a>
    <a class="layui-btn layui-btn-xs layui-icon layui-icon-dollar" lay-event="getBack">取出</a>
</script>
<script type="text/javascript">
    layui.use(['table','jquery','layer','util','laypage','form'],function () {
        var table=layui.table,
            $=layui.jquery,
            layer=layui.layer,
            util=layui.util,
            laypage=layui.laypage,
            form=layui.form;
        var four="";
        var six="";
        //渲染表格
        table.render({
            elem:"#DeposiTable",
            url:"../controller/depositbusiness",
            toolbar: '#Trans_search',
            height:740,
            method:'get',
            limit:15,
            page:true,
            cols:[[
                {checkbox:true},
                {field:"deposiId",title:"存款id",align:"center",width: 200,sort:true},
                {field:"caId",title:"流出账户名称",align:"center",width: 200,templet:function (d) {
                        for (var i=0;i<six.length;i++){
                            if(six[i].caId==d.caId){
                                return six[i].accName;
                            }
                        }
                    },width: 200},
                {field:"caIds",title:"流入账户名称",align:"center",width: 200,templet:function (d) {
                        for (var i=0;i<six.length;i++){
                            if(six[i].caId==d.caIds){
                                return six[i].accName;
                            }
                        }
                    },width: 200},
                {field:"depMoney",title:"存款金额(元)",align:"center",width: 200,templet:function (d) {
                        if (d.depMoney.toString().indexOf(".")!=-1){
                            return d.depMoney.toLocaleString();
                        }else{
                            return (d.depMoney+ '').replace(/(\d{1,3})(?=(\d{3})+(?:$|\.))/g,'$1,')+".00";
                        }
                    }},
                {field:"businType",title:"业务类型",align:"center",templet:function (d) {
                        if(d.businType==1){
                            return "<span style='color: #9BCA63;'>定期</span>";
                        }else if(d.businType==2){
                            return "<span style='color: #FAD860;'>活期</span>";
                        }else{
                            return "<span style='color: #FAD860;'>格式不正确</span>";
                        }
                    },width: 200},
                {field:"expiryDate",title:"到期日期",align:"center",width: 200},
                {field:"handIf",title:"是否处理",align:"center",templet:function (d) {
                        if(d.handIf==1){
                            return "<span style='color: #06b535;'>已处理</span>";
                        }else if(d.handIf==2){
                            return "<span style='color: red;'>未处理</span>";
                        }else{
                            return "<span style='color: #0000FF;'>格式不正确</span>";
                        }
                    },width: 200},
                /*{field:"incl",title:"所含利息",align:"center",width: 200},*/
                {field:"businTime",title:"业务日期",align:"center",width: 200},
                /*{field:"dofa",title:"基金调拨方向",align:"center",width: 200},*/
                {field:"fundId",title:"基金名称",align:"center",sort:true,templet:function (d) {
                        for (var i=0;i<four.length;i++){
                            if(four[i].fundId==d.fundId){
                                return four[i].fundName;
                            }
                        }
                    },width: 200},
                {fixed: 'right', title:'操作', toolbar: '#barDemo',width:250}
            ]],
            limits: [5, 10,20,30,50],
            parseData:function (res) {
                //基金
                four=res.fund;
                var fourStr="<option value=''>--请选择--</option>";
                for (var i = 0; i <four.length; i++) {
                    fourStr+="<option value='"+four[i].fundId+"'>"+four[i].fundName+"</option>";
                }
                $("#fundId").html(fourStr);
                //现金账户
                six=res.cashAccount;
                var sixStr="<option value=''>--请选择--</option>";
                for (var i = 0; i <six.length; i++) {
                    if (six[i].caId==21){
                        sixStr+="<option selected='selected' value='"+six[i].caId+"'>"+six[i].accName+"</option>";
                    }else
                    sixStr+="<option value='"+six[i].caId+"'>"+six[i].accName+"</option>";
                }
                $("#caId").html(sixStr);
                $("#caIds").html(sixStr);
                return {
                    "code":res.code,
                    "msg":res.msg,
                    "count":res.count,
                    "data":res.data
                }
            },
        });
        var mehtod="";
        form.on('submit(formSave)',function (data) {
            //layer(JSON.stringify(data.field));
            //将表单中各字段值转换为json字符串
            //现金库存
            /*var object={"cashId":data.field.deposiId,"fundId":data.field.fundId,
            "caId":data.field.caId,"caMoney":data.field.depMoney,"time":data.field.expiryDate
            }
            var json=JSON.stringify(object);
            $.ajax({
                type:mehtod,
                url: "/Cashcontroller/cashStock",
                data: json,
                dataType:"text",
                contentType:"application/json;charset=utf-8",//前端发送json字符串到后端，必需设置
            });*/
            //ajax提交数据
            //使用ajax删除选中的
            $.ajax({
                type:mehtod,
                url: "/controller/depositbusiness",
                data: JSON.stringify(data.field),
                dataType:"text",
                contentType:"application/json;charset=utf-8",//前端发送json字符串到后端，必需设置
                success:function (msg) {
                    layer.closeAll();//关闭对象框
                    layer.msg(msg);//弹出提示框
                    table.reload("DeposiTable");
                }
            });
            return false;
        });


        table.on('toolbar(DeposiList)',function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            //判断事件event值
            switch(obj.event) {
                //批量删除操作：删除选定的多行数据
                case "batchDel":
                    //获得选中的表格行
                    var data = checkStatus.data;
                    //判断是否大于0行
                    if(data.length>0){
                        layer.confirm('请确认是否真的删除?', function(index){
                            //获取所有选择的id
                            var deposiIdStr="";
                            for (var i = 0; i < data.length; i++) {
                                deposiIdStr = deposiIdStr+data[i].deposiId+",";//累加字符
                            }
                            //去掉最后多余的逗号
                            deposiIdStr=deposiIdStr.substring(0,deposiIdStr.length-1);
                            layer.close(index);
                            var cashIdStr=deposiIdStr;
                            /*$.ajax({
                                type: "put",//提交方式为post
                                url: "/Cashcontroller/batchBel/"+cashIdStr,//后台Servlet路径
                            });*/
                            //使用ajax删除选中的
                            $.ajax({
                                type: "put",//提交方式为post
                                url: "/controller/deposi/"+deposiIdStr,//后台Servlet路径
                                success: function(msg){
                                    layer.msg('删除成功');
                                    //重新加载表格数据
                                    table.reload('DeposiTable');
                                }
                            });
                        });
                    }else{
                        //没有选择数据行
                        layer.msg('你至少选一行！');
                    }
                    break;
                case 'add':
                    //显示添加界面
                    mehtod="post";
                    //清空表单
                    $("#DeposiForm")[0].reset();
                    layer.open({
                        type: 1,//外部页面为2，内部层1
                        title: "<span style='color:white' align='center'><i class='layui-icon'>&#xe61f;</i> 添加新权益数据</span>",
                        area: ['80%', '45%'],
                        fix: false,
                        maxmin: true,
                        shadeClose: true,
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content:$("#data-main").html(),
                        anim:1
                    });
                    //将主键设置成允许修改[防止因先修改，后增加时，该字段被设置为只读]
                    $("input[name='deposiId']").prop("readonly",false);
                    break;
                case "okk":
                    //获得选中的表格行
                    var data = checkStatus.data;
                    //判断是否大于0行
                    if(data.length>0){
                        layer.confirm('请确认是否真的结算?', function(index){
                            //获取所有选择的id
                            var deposiIdStr="";
                            for (var i = 0; i < data.length; i++) {
                                deposiIdStr = deposiIdStr+data[i].deposiId+",";//累加字符
                            }
                            //去掉最后多余的逗号
                            deposiIdStr=deposiIdStr.substring(0,deposiIdStr.length-1);
                            layer.close(index);
                            /*var cashIdStr=deposiIdStr;
                            $.ajax({
                                type: "put",//提交方式为post
                                url: "/Cashcontroller/batchBel/"+cashIdStr,//后台Servlet路径
                            });*/
                            //使用ajax删除选中的
                            $.ajax({
                                type: "put",//提交方式为post
                                url: "/controller/finish/"+deposiIdStr,//后台Servlet路径
                                success: function(msg){
                                    if (msg=="success")
                                        layer.msg("结算成功",{icon:1});
                                    else
                                        layer.msg("结算失败",{icon:2});
                                    //重新加载表格数据
                                    table.reload('DeposiTable');
                                }
                            });
                        });
                    }else{
                        //没有选择数据行
                        layer.msg('你至少选一行！');
                    }
                    break;
            }
        });
            table.on("tool(DeposiList)",function (obj) {
                //得到表格行数据
                var data = obj.data;
                //判断事件event值，与lay-event属性比较(使用switch或if梯形结构都可以,前面已经用过switch,
                // 此处使用if梯形结构)
                //判断是否为行修改操作
                if(obj.event == "update"){
                    //将设置表单操作方式为修改
                    mehtod="put";
                    //设置界面信息
                    layer.open({
                        type: 1,
                        title:'修改权益数据',
                        area: ['80%', '50%'],
                        shade: 0.4,
                        skin: 'layui-layer-lan',
                        content: $("#data-main").html(),
                        anim:1
                    });
                    //alert(data.empName+","+data.hiredate);
                    //将当前行数据显示在表单各字段中
                    form.val("DeposiFormTest", {
                        "deposiId": data.deposiId,
                        "caId":data.caId,
                        "caIds":data.caIds,
                        "depMoney":data.depMoney,
                        "businType":data.businType,
                        "expiryDate":data.expiryDate,
                        "businTime":data.businTime,
                        "handIf":data.handIf,
                        "fundId":data.fundId
                    });
                    //将主键设置成只读:不允许修改
                    $("input[name='deposiId']").prop("readonly","readonly");
                    //判断事件event值，与lay-event属性比较(使用switch或if梯形结构都可以,前面已经用过switch,
                    // 此处使用if梯形结构)
                    //判断是否为行修改操作
                    }else if(obj.event == "delete"){//判断是否为行删除操作
                        layer.confirm("真的删除权益数据编为"+data.deposiId+"这行数据吗?", function(index){
                            //执行表格中删除操作
                            obj.del();
                            layer.close(index);
                            /*var cashId=data.deposiId;
                            $.ajax({
                                type: "delete",
                                url: "/Cashcontroller/cashStock/"+cashId,
                            });*/
                            $.ajax({
                                type: "delete",
                                url: "/controller/depositbusiness/"+data.deposiId,
                                success: function(msg){
                                    //重新加载表格数据
                                    layer.msg(msg);
                                    table.reload('DeposiTable');
                                }
                            });
                        });
                    }else if (obj.event=="getBack") {
                        if (data.businType!=2) layer.msg("只可取出活期存款!",{icon:5})
                        else if (data.handIf!=1) layer.msg("该活期尚未结算!",{icon:5})
                        else{
                            $.ajax({
                                type:"delete",
                                url:"../controller/method/delete",
                                data:JSON.stringify(data),
                                contentType:"application/json",
                                success:function (data) {
                                    if (data=="success") layer.msg("success",{icon:1})
                                    else layer.msg("fail",{icon:2})
                                    //重新加载表格数据
                                    table.reload('DeposiTable');
                                }
                            });
                        }
                    }
            });
        form.on("submit(provinceSearch)",function (data) {
            //定义表单数据对象
            var formData=data.field;
            //得到表单数据json字符串
            var json=JSON.stringify(data.field);
            //alert(json);
            //重新加载表格对象
            table.reload("DeposiTable",{
                //页码
                page:{
                    curr:1
                },
                //条件数据，会带到后台
                where:{
                    businType:formData.businType,
                    expiryDate:formData.expiryDate
                }
            });
            return false;
        });
    });
</script>
</blockquote>
</body>
</html>
